package top.chengdongqing.mishop.entities

import jakarta.persistence.CascadeType
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import top.chengdongqing.mishop.enums.OrderStatus
import top.chengdongqing.mishop.enums.PaymentMethod
import java.math.BigDecimal
import java.time.LocalDateTime

@Entity
@Table(name = "orders")
data class Order(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Int = 0,
    var orderNumber: String,
    var userId: Int,
    var productsAmount: BigDecimal,
    var shippingFee: BigDecimal,
    var discountAmount: BigDecimal,
    var paidAmount: BigDecimal,
    var recipientName: String,
    var recipientPhone: String,
    var recipientAddress: String,
    @Enumerated(EnumType.STRING)
    var paymentMethod: PaymentMethod? = null,
    var paymentTime: LocalDateTime? = null,
    var paymentOrderNumber: String? = null,
    var expressName: String? = null,
    var trackingNumber: String? = null,
    var isReviewed: Boolean = false,
    @Enumerated(EnumType.STRING)
    var status: OrderStatus = OrderStatus.PENDING_PAYMENT
) : BaseEntity() {
    @OneToMany(cascade = [CascadeType.PERSIST])
    @JoinColumn(name = "order_id")
    lateinit var items: List<OrderItem>
}